<!--
 * @Description: 周材出库
 * @Autor: wangwangwang
 * @Date: 2021-03-19 15:15:15
 * @LastEditors: wangwangwang
 * @LastEditTime: 2021-03-27 14:07:24
-->
<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main style="display: flex">
        <div>
          <div class="header_right" @click="showCardNav = !showCardNav">
            <div class="title">搜索</div>
            <div>
              <transition name="from"></transition>
              <span v-show="!showCardNav">
                <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
              </span>
              <transition name="to"></transition>
              <span v-show="showCardNav">
                <i style="margin-right: 5px" class="el-icon-arrow-up"></i>
              </span>
            </div>
          </div>
          <div v-show="showCardNav" class="hr"></div>
          <el-collapse-transition>
            <div v-show="showCardNav">
              <div class="search">
                <span style="display: inline-block;margin-bottom: 10px;">
                  <span style="margin-right: 12px">取用工程</span>
                  <el-input v-model="tableParam.engineeringName" style="width: 240px" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
                </span>
                <span style="margin-left: 24px">
                  <span style="margin-right: 12px">状态</span>
                  <el-select v-model="tableParam.materialsStatus " placeholder="请选择" style="width: 120px">
                    <el-option label="全部" :value="null"></el-option>
                    <el-option label="待签收" :value="1"></el-option>
                    <el-option label="已签收" :value="2"></el-option>
                    <el-option label="回收中" :value="3"></el-option>
                    <el-option label="回收完成" :value="4"></el-option>
                  </el-select>
                </span>
                <el-button icon="el-icon-search" size="medium" class="bottom_all" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
                <el-button size="medium" class="bottom_all_two" style="margin-left: 12px" @click="init()">重 置</el-button>
              </div>
            </div>
          </el-collapse-transition>
          <div class="hr"></div>
          <div class="card">
            <div class="card_nav">
              <div>
                <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='ZOUCAICHUKU'))!==-1" size="small" class="bottom_all_two" style="margin-left: 0" @click="open('dialog1')">
                  周材出库
                </el-button>
                <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='XUNJIANJILU'))!==-1" size="small" class="bottom_all_two" style="margin-left: 12px" @click="open('dialog2')">
                  巡检记录
                </el-button>
                <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='TJGDFZR'))!==-1" size="small" class="bottom_all_two" style="margin-left: 12px" @click="open('dialog3')">
                  添加工地负责人
                </el-button>
              </div>
              <div>
                <el-dropdown :hide-on-click="false" trigger="click" style="margin: 0 20px">
                  <el-link :underline="false">
                    <span class="el-icon--left">
                      <i class="iconfont iconicon_button_filtrate"></i>
                    </span>
                    筛选
                  </el-link>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item v-for="(item, index) in table" :key="index">
                      <el-checkbox v-model="item.status">{{
                        item.label
                        }}</el-checkbox>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
            </div>
            <div v-loading="tableLoading" class="card_info" :style="style">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="tableData" tooltip-effect="dark">
                <template v-for="(item, index2) in table">
                  <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :min-width="item.width" :fixed="item.label =='操作'?'right':false" :show-overflow-tooltip="item.label =='出库备注'">
                    <template slot-scope="scope">
                      <span v-if="item.label == '状态'">
                        <span v-if="scope.row.materialsStatus == 1" style="color: #969799">待签收 </span>
                        <span v-if="scope.row.materialsStatus == 2" style="color: #00a754">已签收</span>
                        <span v-if="scope.row.materialsStatus == 3" style="color: #969799">回收中</span>
                        <span v-if="scope.row.materialsStatus == 4" style="color: #00a754">回收完成</span>
                      </span>
                      <div v-else-if="item.label == '取用工程'">
                        <span v-if="scope.row.takeStatus==1">自用</span>
                        <span v-else>{{scope.row.engineeringName}}</span>
                      </div>
                      <div v-else-if="item.label == '工地负责人'">
                        <span v-if="scope.row.takeStatus==1">-</span>
                        <el-button v-else-if="ButtonList.findIndex(res=>(res.buttonValue=='CHAKAN'))!==-1" class="bottom_one" size="mini" @click="open1('dialog4',scope.row.storagePeoples)">
                          查看
                        </el-button>
                      </div>
                      <div v-else-if="item.label == '运输安排'">
                        <span v-if="scope.row.takeStatus==1">-</span>
                        <el-button v-else-if="ButtonList.findIndex(res=>(res.buttonValue=='CHAKAN'))!==-1" class="bottom_one" size="mini" @click="open1('dialog5',scope.row.storageCars)">
                          查看
                        </el-button>
                      </div>
                      <div v-else-if="item.label == '操作'">
                        <el-button class="bottom_one" size="mini" @click="open1('dialog6',scope.row)">
                          周材明细
                        </el-button>
                      </div>
                      <span v-else>{{ scope.row[item.prop] }}</span>
                    </template>
                  </el-table-column>
                </template>
              </el-table>
            </div>
          </div>
        </div>
      </el-main>
      <div class="card_bottom">
        <div class="card_bottom_left">
          <div class="top_page_totle">总共{{ total }}条</div>
          <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" layout="prev, pager, next, jumper" :total="total" @current-change="gettableData()"></el-pagination>
        </div>
        <div>
          <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
        </div>
      </div>
    </el-container>
    <!-- 周材出库 -->
    <el-dialog v-dialogDrag :visible.sync="dialog1" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">周材出库</span>
      <div>
        <div class="dialogTitle">出库概要</div>
        <el-form ref="reffromDate" :rules="rules" :inline="true" :model="mOutStorage" label-width="110px">
          <div style="display:flex;  justify-content: space-between;">
            <el-form-item prop="takeStatus">
              <span slot="label">出库原因</span>
              <el-radio-group v-model="mOutStorage.takeStatus">
                <el-radio :label="1">自用</el-radio>
                <el-radio :label="2">工地取用</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item v-if="mOutStorage.takeStatus==2" prop="engineeringId">
              <span slot="label" style="color: #ff0000">取用工程</span>
              <el-select v-model="mOutStorage.engineeringId" placeholder="请选择" @change="change1(mOutStorage.engineeringId)">
                <el-option v-for="(item, index) in engineeringList" :key="index" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div v-if="mOutStorage.takeStatus==2" style="display:flex;  justify-content: space-between;">
            <el-form-item>
              <span slot="label">工程地址</span>
              <div style="width:280px">{{mOutStorage.place}}</div>
            </el-form-item>
            <el-form-item>
              <span slot="label">出库日期</span>
              <div style="width:280px">{{new Date().Format('yyyy-MM-dd hh:mm:ss')}}</div>
            </el-form-item>
          </div>
          <div v-if="mOutStorage.takeStatus==2">
            <el-form-item prop="principal1">
              <span slot="label" style="color: #ff0000">工地负责人</span>
              <el-select v-model="mOutStorage.principal1" multiple placeholder="请选择" @change="change3(mOutStorage.principal1)">
                <el-option v-for="(item, index) in userList" :key="index" :label="item.principal" :value="item.principalId"></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div>
            <el-form-item>
              <span slot="label">出库备注</span>
              <el-input v-model="mOutStorage.remark" style="width:680px" placeholder="请填写备注" class="textarea" type="textarea" resize="none" rows="5"></el-input>
            </el-form-item>
          </div>
        </el-form>
        <div class="dialogTitle">周材明细</div>
        <div style="padding-bottom:10px">
          <el-button size="mini" class="bottom_all" style="margin-left: 0" @click="addItem1()">
            <i class="icon iconfont iconicon_button_add" style="font-size: 12px"></i>
            添加
          </el-button>
        </div>
        <div style="padding-bottom:20px">
          <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="particulars">
            <el-table-column label="名称" align="center">
              <template slot-scope="scope">
                <el-select v-model="scope.row.name" style="width:100%" placeholder="请选择" @change="change4(scope.row)">
                  <el-option v-for="(item, index) in nameList" :key="index" :value="item"></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="规格" align="center">
              <template slot-scope="scope">
                <el-select v-model="scope.row.specificationId" :disabled="scope.row.specificationList.length==0" style="width:100%" placeholder="请选择" @change="change5(scope.row)">
                  <el-option v-for="(item, index) in scope.row.specificationList" :key="index" :label="item.specificationName" :value="item.specificationId"></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="类型" align="center">
              <template slot-scope="scope">
                <el-select v-model="scope.row.typeId" :disabled="scope.row.typeList.length==0" style="width:100%" placeholder="请选择" @change="change6(scope.row)">
                  <el-option v-for="(item, index) in scope.row.typeList" :key="index" :label="item.type" :value="item.typeId"></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="在库数量" align="center" prop="repertoryAmount"></el-table-column>
            <el-table-column label="出库数量" align="center">
              <template slot-scope="scope">
                <el-input v-model="scope.row.stockOutAmount" :disabled="scope.row.typeId==''" style="width:100%" placeholder="请输入" clearable onkeypress='return( /\d/.test(String.fromCharCode(event.keyCode)))' @input="scope.row.stockOutAmount=$regExp.checkNum(scope.row.stockOutAmount)" @blur="scope.row.stockOutAmount=$regExp.blurCheckNum(scope.row.stockOutAmount),stockOutAmountFun(scope.row)">
                  <template slot="append">个</template>
                </el-input>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="left">
              <template slot-scope="scope">
                <el-button size="mini" class="bottom_two" @click="delItem1(scope.$index)">
                  <i class="icon iconfont iconicon_button_delete" style="font-size: 12px"></i>
                  删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div v-if="mOutStorage.takeStatus==2" class="dialogTitle">运输安排</div>
        <div v-if="mOutStorage.takeStatus==2" style="padding-bottom:10px">
          <el-button size="mini" class="bottom_all" style="margin-left: 0" @click="additem2()">
            <i class="icon iconfont iconicon_button_add" style="font-size: 12px"></i>
            添加
          </el-button>
        </div>
        <div v-if="mOutStorage.takeStatus==2" style="padding-bottom:20px">
          <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="storageCars">
            <el-table-column label="运输负责人" align="center">
              <template slot-scope="scope">
                <el-select ref="driverId" v-model="scope.row.driverId " style="widrh:100%;max-width:200px" placeholder="请选择" @change="$nextTick(()=>{scope.row.driver = $refs.driverId.selectedLabel})">
                  <el-option v-for="(item, index) in driverList" :key="index" :label="item.name" :value="item.id"></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="运输车辆" align="center">
              <template slot-scope="scope">
                <el-select v-model="scope.row.plateNumber " style="widrh:100%;max-width:200px" placeholder="请选择">
                  <el-option v-for="(item, index) in plateNumberList" :key="index" :value="item.plateNumber"></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="left">
              <template slot-scope="scope">
                <el-button size="mini" class="bottom_two" @click="delItem2(scope.$index)">
                  <i class="icon iconfont iconicon_button_delete" style="font-size: 12px"></i>
                  删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="reset('dialog1')">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="submit0()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 巡检记录 -->
    <el-dialog v-dialogDrag :visible.sync="dialog2" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">巡检记录</span>
      <div>
        <div style="padding-bottom:20px">
          <span style="margin-left: 24px">
            <span style="margin-right: 12px">选择工程</span>
            <el-select v-model="engineeringId" placeholder="请选择">
              <el-option v-for="(item, index) in engineeringList" :key="index" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </span>
          <el-button :disabled="engineeringId==''" icon="el-icon-search" size="medium" class="bottom_all" @click="getarr()">查 询</el-button>
        </div>
        <div>
          <div class="tabtop">
            <div v-for="(item, index) in navList2" :key="index" @click="currenindex2=item.id,getarr()">
              <div :class="currenindex2 == index ? 'active' : 'text'">{{ item.value }}</div>
              <div v-if="currenindex2 !== index && currenindex2 !== index + 1 && index !== 2" class="hr"></div>
            </div>
          </div>
        </div>
        <el-table v-if="currenindex2==0" :key="0" :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="lowData">
          <!-- <el-table-column label="序号" align="center" prop="code"></el-table-column> -->
          <el-table-column label="巡检结果" align="center">
            <template slot-scope="scope">
              {{scope.row.qualityStatus==1?'正常':'变化'}}
            </template>
          </el-table-column>
          <el-table-column label="缺失周材名称" align="center" prop="name">
            <template slot-scope="scope">
              {{scope.row.name||'--'}}
            </template>
          </el-table-column>
          <el-table-column label="规格" align="center" prop="specificationName">
            <template slot-scope="scope">
              {{scope.row.specificationName||'--'}}
            </template>
          </el-table-column>
          <el-table-column label="等级/类型" align="center" prop="type">
            <template slot-scope="scope">
              {{scope.row.type||'--'}}
            </template>
          </el-table-column>
          <el-table-column label="巡检日期" align="center" prop="createTime"></el-table-column>
          <el-table-column label="提交人员" align="center" prop="createUserName"></el-table-column>
        </el-table>
        <el-table v-if="currenindex2==1" :key="1" :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="lowData">
          <el-table-column label="巡检结果" align="center">
            <template slot-scope="scope">
              {{scope.row.qualityStatus==1?'正常':'变化'}}
            </template>
          </el-table-column>
          <el-table-column label="质量变化周材名称" align="center" prop="name">
            <template slot-scope="scope">
              {{scope.row.name||'--'}}
            </template>
          </el-table-column>
          <el-table-column label="规格" align="center" prop="specificationName">
            <template slot-scope="scope">
              {{scope.row.specificationName||'--'}}
            </template>
          </el-table-column>
          <el-table-column label="类型" align="center" prop="type">
            <template slot-scope="scope">
              {{scope.row.type||'--'}}
            </template>
          </el-table-column>
          <el-table-column label="质量变化处理建议" align="center" prop="remark">
            <template slot-scope="scope">
              {{scope.row.remark||'--'}}
            </template>
          </el-table-column>
          <el-table-column label="变化周材数量" align="center" prop="account"></el-table-column>
          <el-table-column label="巡检日期" align="center" prop="createTime"></el-table-column>
          <el-table-column label="巡检人员" align="center" prop="createUserName"></el-table-column>
        </el-table>
        <el-table v-if="currenindex2==2" :key="2" :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="lowData">
          <el-table-column label="巡检结果" align="center">
            <template slot-scope="scope">
              {{scope.row.safetyStatus==1?'符合安全情况':'存在安全隐患'}}
            </template>
          </el-table-column>
          <el-table-column label="处理状态" align="center">
            <template slot-scope="scope">
              {{scope.row.disposeStatus==1?'未处理':'已处理'}}
            </template>
          </el-table-column>
          <el-table-column label="巡检日期" align="center" prop="createTime"></el-table-column>
          <el-table-column label="提交人员" align="center" prop="createUserName"></el-table-column>
          <el-table-column label="详情" align="center">
            <template slot-scope="scope">
              <el-link class="table_link" :underline="false" @click="picture(scope.row)">查看</el-link>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="reset('dialog2')">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 添加工地负责人 -->
    <el-dialog v-dialogDrag :visible.sync="dialog3" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">添加工地负责人</span>
      <div>
        <div style="padding-bottom:20px">
          <span style="margin-left: 24px">
            <span style="margin-right: 12px">选择工程</span>
            <el-select ref="engineeringName" v-model="engineeringId" style="width:220px;" placeholder="请选择" @change="dialog3loading=true,$nextTick(()=>{engineeringName = $refs.engineeringName.selectedLabel},lowList=[]),getlowList()">
              <el-option v-for="(item, index) in engineeringList" :key="index" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </span>
        </div>
        <div style="padding-bottom:10px">
          <el-button :disabled="engineeringId==''" size="mini" class="bottom_all" style="margin-left: 0" @click="addItem()">
            <i class="icon iconfont iconicon_button_add" style="font-size: 12px"></i>
            添加
          </el-button>
        </div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark
        " :data="lowList">
          <el-table-column label="序号" align="center">
            <template slot-scope="scope">{{scope.$index + 1}}
            </template>
          </el-table-column>
          <el-table-column label="负责人" align="center">
            <template slot-scope="scope">
              <div v-if="scope.row.id">{{scope.row.principal}}</div>
              <el-select v-else v-model="scope.row.principalId" style="width:100%" placeholder="请选择" @change="change2(scope.row)">
                <el-option v-for="(item, index) in userList0" :key="index" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="联系电话" align="center" prop="phone">
          </el-table-column>
          <el-table-column label="添加日期" align="center" prop="createTime"></el-table-column>
          <el-table-column label="备注" align="center">
            <template slot-scope="scope">
              <div v-if="scope.row.id">{{scope.row.remark}}</div>
              <el-input v-else v-model="scope.row.remark" style="width:100%" placeholder="请输入" clearable>
              </el-input>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="left">
            <template slot-scope="scope">
              <el-button v-if="!scope.row.id" size="mini" class="bottom_two" @click="delItem(scope.$index)">
                <i class="icon iconfont iconicon_button_delete" style="font-size: 12px"></i>
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="reset('dialog3')">取 消</el-button>
        <el-button class="bottom_all" @click="submit2()">保 存</el-button>
      </span>
    </el-dialog>
    <!-- 工地负责人 -->
    <el-dialog v-dialogDrag :visible.sync="dialog4" width="680px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">工地负责人</span>
      <div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="lowData">
          <el-table-column label="工地负责人" align="center" prop="principal"></el-table-column>
          <el-table-column label="联系电话" align="center" prop="phone"></el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="reset('dialog4')">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 运输安排 -->
    <el-dialog v-dialogDrag :visible.sync="dialog5" width="680px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">运输安排</span>
      <div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="lowData">
          <el-table-column label="运输负责人" align="center" prop="driver"></el-table-column>
          <el-table-column label="运输车辆" align="center" prop="plateNumber"></el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="reset('dialog5')">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 查看周材详情 -->
    <el-dialog v-dialogDrag :visible.sync="dialog6" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">查看周材详情</span>
      <div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="lowData">
          <el-table-column label="序号" align="center" prop="code"></el-table-column>
          <el-table-column label="周材名称" align="center" prop="name"></el-table-column>
          <el-table-column label="规格" align="center" prop="specificationName"></el-table-column>
          <el-table-column label="类型" align="center" prop="type"></el-table-column>
          <el-table-column label="计划出库数量" align="center" prop="stockOutAmount"></el-table-column>
          <el-table-column label="已签收数量" align="center" prop="signAmount"></el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="reset('dialog6')">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 查看图片 -->
    <el-dialog v-dialogDrag :visible.sync="imgsDialog" width="700px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">图片信息</span>
      <div style="padding:10px;">
        <template v-for="(item1, index1) in arr">
          <div :key="index1" style="padding-bottom:15px;">
            <div class="dialogTitle">{{item1.dangerTitle}}</div>
            <div class="dialogTitle2">{{item1.hiddenDanger}}</div>
            <div style="padding-bottom:15px;">
              <span v-for="(item, index) in item1.srcList" :key="index">
                <el-image v-if="$options.filters.imgMp4TypeFun(item) == 'img'" :src="item" :preview-src-list="item1.srcList" style="width:200px;height:200px;margin:5px 10px;box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.35);" :z-index="10000" @click="srcList=[item]"></el-image>
                <video v-else width="200" height="200" style="margin:5px 10px;box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.35);" :src="item" controls>您的浏览器不支持 HTML5 video 标签。</video>
              </span>
              <!-- <el-image style="width: 200px; height:200px;margin:0 10px 10px 10px;border-radius: 4px;" :src="item" :preview-src-list="item1.srcList" :z-index="10000"></el-image> -->
            </div>
            <div class="dialogTitle">{{item1.methodTitle}}</div>
            <div class="dialogTitle2">{{item1.solution}}</div>
            <div>
              <span v-for="(item, index) in item1.srcList1" :key="index">
                <el-image v-if="$options.filters.imgMp4TypeFun(item) == 'img'" :src="item" :preview-src-list="item1.srcList" style="width:200px;height:200px;margin:5px 10px;box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.35);" :z-index="10000" @click="srcList=[item]"></el-image>
                <video v-else width="200" height="200" style="margin:5px 10px;box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.35);" :src="item" controls>您的浏览器不支持 HTML5 video 标签。</video>
              </span>
              <!-- <el-image v-for="(item, index) in item1.srcList1" :key="index" style="width: 200px; height:200px;margin:0 10px 10px 10px;border-radius: 4px;" :src="item" :preview-src-list="item1.srcList1" :z-index="10000"></el-image> -->
            </div>
          </div>
        </template>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="imgsDialog = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import {
  queryPage, queryListMaterials, queryList, get_simple_user_listBycompanyId, saveOneResord, queryNameList, querySpecification, queryListCar, saveOutStorage, particularsList, patrolQuality, patrolSafety, hiddenDanger
} from "@/api/besSer/WMmanagement/outbound.js";
import { getUserInfo } from "@/utils/auth"
export default {
  mixins: [mixin],
  data() {
    return {
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      /*表格数据*/
      table: [
        // { label: "序号", width: "auto", prop: "", status: true },
        { label: "取用工程", width: "120", prop: "engineeringName", status: true },
        { label: "出库单号", width: "90", prop: "stockOutNumber", status: true },
        { label: "出库数量", width: "60", prop: "takeAmount", status: true },
        { label: "出库日期", width: "100", prop: "createTime", status: true },
        { label: "工地负责人", width: "120", prop: "", status: true },
        { label: "出库备注", width: "auto", prop: "remark", status: true },
        { label: "运输安排", width: "auto", prop: "", status: true },
        { label: "状态", width: "auto", prop: "", status: true },
        { label: "操作", width: "120", prop: "", status: true },
      ],
      pagesType: 0,
      /*添加表单数据*/
      rules: {
        engineeringId: [{ required: true, message: "请选择工程", trigger: "change" }],
        principal1: [{ required: true, message: "请选择工程负责人", trigger: "change" }],
      },
      dialog1: false,
      dialog2: false,
      dialog3: false,
      dialog4: false,
      dialog5: false,
      dialog6: false,
      navList2: [
        { id: 0, value: '数量情况' },
        { id: 1, value: '质量情况' },
        { id: 2, value: '安全情况' },
      ],
      currenindex2: 0,
      lowData: [],
      mOutStorage: {
        takeStatus: 1,
        engineeringId: '',
        place: '',
        principal1: []
      },
      storagePeoples: [],
      particulars: [],
      storageCars: [],
      nameList: [],
      engineeringList: [],
      plateNumberList: [],
      driverList: [],
      userList: [],
      userList0: [],
      engineeringId: '',
      engineeringName: '',
      lowList: [],
      dialog3loading: true,
      imgsDialog: false,
      arr: []
    };
  },
  created() {
    /*存储拷贝的原初始化fromDate数据*/
    this.tableParam = { ...this.tableParam, engineeringName: "", materialsStatus: "" };
    this.gettableData();
  },
  filters: {
    imgMp4TypeFun(d) {
      if (d.includes("jpeg") || d.includes("jpg") || d.includes("png")) {
        return "img";
      } else {
        return "mp4";
      }
    },
  },
  methods: {
    /**安全情况查看*/
    picture(low) {
      console.log(low)
      hiddenDanger({ id: low.id, disposeStatus: low.disposeStatus }).then(res => {
        if (res.data.hiddenDangers) {
          res.data.hiddenDangers.forEach(res => {
            if (res.hiddenDangerPath) {
              res.srcList = res.hiddenDangerPath.split(',')
              res.srcList = res.srcList.map(res => ('file/' + res))
            }
            if (res.solutionPath) {
              res.srcList1 = res.solutionPath.split(',')
              res.srcList1 = res.srcList1.map(res => ('file/' + res))
            }
          });
        }
        this.arr = res.data.hiddenDangers
      })
      this.imgsDialog = true;
    },
    /**巡检记录*/
    getarr() {
      if (this.engineeringId == '') {
        return
      }
      if (this.currenindex2 == 0) {
        patrolQuality({ engineeringId: this.engineeringId, category: 1 }).then(res => {
          this.lowData = res.data
          this.$forceUpdate()
        })
      }
      if (this.currenindex2 == 2) {
        patrolSafety({ engineeringId: this.engineeringId }).then(res => {
          this.lowData = res.data
          this.$forceUpdate()
        })
      }
      if (this.currenindex2 == 1) {
        patrolQuality({ engineeringId: this.engineeringId, category: 2 }).then(res => {
          this.lowData = res.data
          this.$forceUpdate()
        })
      }
    },
    /**周材出库*/
    async change1(id) {
      let a = this.engineeringList.find(res => (res.id == id))
      this.mOutStorage.engineeringName = a.name
      this.mOutStorage.place = a.place
      const { data } = await queryList({ engineeringId: id })
      this.userList = data
      this.mOutStorage.principal1 = []
    },
    change3(arr) {
      this.storagePeoples = arr.map(item => {
        let a = this.userList.find(res => (res.principalId == item))
        return {
          principal: a.principal,
          principalId: a.principalId,
          phone: a.phone
        }
      })
      this.mOutStorage.principal = this.storagePeoples.map(res => (res.principal)).join(',')
      this.mOutStorage.phone = this.storagePeoples.map(res => (res.phone)).join(',')

    },
    addItem1() {
      this.particulars.push({
        repertoryAmount: '',
        stockOutAmount: '',
        repertoryManageId: '',
        name: '',
        specificationName: '',
        specificationId: '',
        type: '',
        typeId: '',
        typeList: [],
        specificationList: []
      })
    },
    delItem1(index) {
      this.particulars.splice(index, 1)
    },
    async change4(low) {
      const { data } = await querySpecification({ name: low.name, companyId: getUserInfo().companyId })
      low.specificationList = data
      low.specificationId = ''
      low.typeList = []
      low.typeId = ''
      low.repertoryAmount = ''
    },
    change5(low) {
      let a = low.specificationList.find(res => (res.specificationId == low.specificationId))
      low.specificationName = a.specificationName
      low.typeList = a.typeList
      low.typeId = ''
      low.repertoryAmount = ''
    },
    change6(low) {
      let a = low.typeList.find(res => (res.typeId == low.typeId))
      low.type = a.type
      low.repertoryManageId = a.id
      low.repertoryAmount = a.repertoryAmount - a.notSignamount - a.stockOutAmount
    },
    additem2() {
      this.storageCars.push({
        driver: '',
        driverId: '',
        plateNumber: ''
      })
    },
    delItem2(index) {
      this.storageCars.splice(index, 1)
    },
    submit0() {
      let _this = this;
      _this.$refs.reffromDate.validate((valid) => {
        if (valid) {
          if (_this.particulars.length == 0 || !_this.particulars[0].name) {
            this.$message({
              message: '警告哦，请添加周材',
              type: 'warning'
            });
            return
          }
          if (this.mOutStorage.takeStatus == 2 && (_this.storageCars.length == 0 || !_this.storageCars[0].driverId)) {
            _this.$message({
              message: '请选择运输负责人',
              type: 'warning'
            });
            return
          }
          let hash = {};
          const deWeight = (item, cur) => {
            hash[cur.repertoryManageId] ? '' : hash[cur.repertoryManageId] = true && item.push(cur);
            return item
          }
          let arr = _this.particulars.reduce(deWeight, [])
          if (arr.length !== _this.particulars.length) {
            _this.$message({
              message: '警告哦，请不要重复添加周材',
              type: 'warning'
            });
            return
          }
          const sum = (prev, cur) => (prev + Number(cur.stockOutAmount || 0))
          _this.mOutStorage.takeAmount = _this.particulars.reduce(sum, 0)
          let obj = {
            particulars: _this.particulars,
            storagePeoples: _this.storagePeoples,
            storageCars: _this.storageCars,
            mOutStorage: _this.mOutStorage
          }
          saveOutStorage(obj).then(res => {
            if (res.code == 1001) {
              _this.$message({
                message: '添加成功',
                type: 'success'
              });
              _this.reset('dialog1')
              _this.gettableData();
            }
          })
          console.log(obj)
        } else {
          return false;
        }
      });

    },
    /**添加工地负责人*/
    async getlowList() {
      const { data } = await queryList({ engineeringId: this.engineeringId })
      this.lowList = data

      // const { data: data1 } = await get_simple_user_listBycompanyId({ orgznizationId: this.engineeringList.find((res) => res.id == this.engineeringId).companyId, roleId: '5b1ca600fb4f4a7e898506bc803449f6' })//工地周材负责人
      const { data: data1 } = await get_simple_user_listBycompanyId({ roleId: '5b1ca600fb4f4a7e898506bc803449f6' })//工地周材负责人
      this.userList0 = data1
    },
    addItem() {
      this.lowList.push({
        principalId: '',
        principal: '',
        phone: '',
        remark: '',
        engineeringId: this.engineeringId,
        engineeringName: this.engineeringName,
        createTime: new Date().Format('yyyy-MM-dd hh:mm:ss')
      })
    },
    delItem(index) {
      this.lowList.splice(index, 1)
    },
    change2(low) {
      let a = this.userList0.find(res => (res.id == low.principalId))
      low.principal = a.name
      low.phone = a.phone
    },
    async submit2() {
      if (this.lowList.length == 0) {
        this.$message({
          message: '警告哦，请添加负责人',
          type: 'warning'
        });
        return
      }
      if (this.lowList.findIndex((res) => res.principalId == '') != -1) {
        this.$message({
          message: '负责人不能为空',
          type: 'warning'
        });
        return
      }
      let hash = {};
      const deWeight = (item, cur) => {
        hash[cur.principalId] ? '' : hash[cur.principalId] = true && item.push(cur);
        return item
      }
      let arr = this.lowList.reduce(deWeight, [])
      if (arr.length !== this.lowList.length) {
        this.$message({
          message: '警告哦，请不要重复添加负责人',
          type: 'warning'
        });
        return
      }
      let dataarr = this.lowList.filter(res => (!res.id))
      const { code } = await saveOneResord(dataarr)
      if (code == 1001) {
        this.$message({
          message: '添加成功',
          type: 'success'
        });
        this.reset('dialog3')
      }
    },
    async open(key) {
      this.userList = []
      if (key == 'dialog1') {
        this.$data.mOutStorage = this.$options.data().mOutStorage
        const { data } = await queryListMaterials({ companyId: getUserInfo().companyId })
        const { data: list } = await queryNameList()
        const { data: driver } = await get_simple_user_listBycompanyId({ orgznizationId: getUserInfo().companyId, roleId: '12719832957063168' })//周材司机
        const { data: plateNumber } = await queryListCar({ companyId: getUserInfo().companyId, carTypeId: '0c51dc71d20b4a1cb35645156d6a820d' })//车辆类型-东风车
        this.plateNumberList = plateNumber
        this.driverList = driver
        this.nameList = list
        this.particulars = []
        this.storageCars = []
        this.engineeringList = data
      }
      if (key == 'dialog3') {
        const { data } = await queryListMaterials({ companyId: getUserInfo().companyId })
        this.engineeringList = data
        this.engineeringId = ''
        this.lowList = []
      }
      if (key == "dialog2") {
        const { data } = await queryListMaterials({ companyId: getUserInfo().companyId })
        this.engineeringList = data
      }
      this[key] = true
    },
    async open1(key, low) {
      if (key == "dialog6") {
        const { data } = await particularsList({ outStorageId: low.id })
        this.lowData = data
      } else {
        this.lowData = low
      }

      this[key] = true
    },
    reset(key) {
      this[key] = false
    },
    /*重置数据,此方法必须存在，并且方发只重置条件*/
    init() {
      this.tableParam.engineeringName = "";
      this.tableParam.materialsStatus = "";
      this.gettableData();
    },
    stockOutAmountFun(row) {
      if (row.stockOutAmount > row.repertoryAmount) {
        this.$message({
          message: '出库数量不能大于在库数量！',
          type: 'warning'
        });
        row.stockOutAmount = row.repertoryAmount
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.tabtop {
  width: 570px;
  margin: 20px 0 20px 0;
}
.dialogTitle {
  font-size: 16px;
  font-weight: bold;
  padding: 0 0 10px;
}
.dialogTitle2 {
  padding-left: 20px;
  height: 19px;
}
.el-input,
.el-select {
  width: 280px;
}
/*
 <el-link class="table_link" :underline="false">查看配合比</el-link>*/
.table_link {
  margin: 0 10px;
  color: $bg_color;
  cursor: pointer;
}

.table_link:hover {
  opacity: 0.8;
}
</style>
